﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Core.Constants;
using Core.Email;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;
using Utils;

namespace LoggerService
{
    public class BaseLogger
    {
        IEmailer _emailService;

        public BaseLogger(IUnityContainer Container)
        {
            
            _emailService = Container.Resolve<IEmailer>();
        }

        public virtual void Log(string message)
        {
            EmailLog(message);
            FlatFileLog(message);
        }

        private void EmailLog(string message)
        {
            _emailService.SendSingleEmail(ConfigUtils.GetSingleWebConfigSetting(ConstantsError.STR_SITE_ERROR_ADDRESS), ConstantsError.STR_SITE_ERROR, message);
        }

        private void FlatFileLog(string message)
        {

            FileManager.WriteLineToTxtFile(String.Format(@"{0}Logs\Log.txt", PathManager.GetWebAppPath()), String.Format("{0}: {1}", DateTime.Now, message));
        }
    }
}
